﻿using System;
using System.Collections.ObjectModel;
using System.Text;
using MUD.Lib.Utils;
using MUD.Lib.Objects.Domains;
using MUD.Lib.Objects.Users;

namespace MUD.Lib.Objects.Rooms
{
    internal class Room : Container
    {
        public Domain Domain;

        public Collection<Exit> Exits = new Collection<Exit>();

        public string[] ExitDirs
        {
            get
            {
                string[] temp = new string[Exits.Count];
                for(int i = 0; i < Exits.Count; i++)
                {
                    temp[i] = Exits[i].ID;
                }
                return temp;
            }
        }

        public Room(Domain domain)
        {
            Domain = domain;
            domain[this.GetType()] = this;
            Initialize();
            // TODO: Step over this again and make sure my logic is sound here.
        }

        public virtual void Initialize()
        {
            foreach (Exit exit in Exits)
            {
                exit.Initialize(Domain, this);
            }
        }

        public override void Add(MudObject item)
        {
            base.Add(item);

            if (item is User)
            {
                ListenToUser((User)item);
            }
        }

        public override void Remove(MudObject item)
        {
            if (item is User)
                StopListeningToUser((User)item);

            base.Remove(item);
        }
    }
}
